package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.PrivateMessage;
import cn.wolfcode.trip.base.query.PrivateMessageQueryObject;
import cn.wolfcode.trip.base.service.IPrivateMessageService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/privateMessages")
public class PrivateMessageController {
    @Autowired
    private IPrivateMessageService privateMessageService;

    /**
     * 发送消息
     *
     * @return
     */
    @PostMapping
    public Object sendMessage(PrivateMessage entity) {
        privateMessageService.send(entity);
        return new JSONResult();
    }

    /**
     * 根据发送者,接收者id查询信息
     */
    @GetMapping("/{senderId}/{receiverId}")
    public Object queryMessagesByBoth(PrivateMessageQueryObject qo) {
        qo.setPageSize(20);
        qo.setOrderBy("sendTime");
        PageInfo pageInfo=privateMessageService.queryMessagesByBothId(qo);
        return pageInfo;
    }

    @PutMapping()
    public Object readMessage(PrivateMessageQueryObject qo){
       privateMessageService.readMessage(qo);
        return new JSONResult();
    }
}
